package com.common.www.bean.entity.recycle;

import com.common.www.MyApplicationListener;
import org.springframework.boot.base.jpa.domain.entity.NumberIdentityEntity;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;

import java.util.List;

import javax.persistence.*;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 回收品类
 */
@DynamicUpdate(false)
@DynamicInsert(false)
@Getter
@Setter
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@NoArgsConstructor
@AllArgsConstructor
@Table()
@JsonIgnoreProperties(value = {})
public class RecycleType extends NumberIdentityEntity {

    private static final long serialVersionUID = -2278084748058910042L;

    @JsonIgnoreProperties(value = {"parent", "children"})
    @ManyToOne()
    @JoinColumn(name = "parent")
    private RecycleType parent;

    //二级分类
    @JsonIgnoreProperties(value = {"parent"})
    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "parent")
    @OrderBy("sort asc")
    @Where(clause = "flag = 1")
    private List<RecycleType> children;

    /**
     * 类型名称名称
     */
    @Column(length = 128)
    private String name;

    /**
     * 类型描述
     */
    @Column(length = 512)
    private String description;
    /**
     * 节点地址
     */
    @Column(length = 256)
    private String nodePath;

    /**
     * 排序数字大小，数字越小排列在越前面
     */
    @Column(length = 30)
    private Integer sort;
    /**
     * 节点等级
     */
    @Column(length = 30)
    private Integer level;


//    /**
//     * 最低单价 元/kg 或元/吨 等，根据物品的类型来定
//     */
//    @Column(precision = 23, scale = 2)
//    private BigDecimal minPrice;
//    /**
//     * 最高单价 元/kg 或元/吨 等，根据物品的类型来定
//     */
//    @Column(precision = 23, scale = 2)
//    private BigDecimal maxPrice;
//    /**
//     * 建议单价 元/kg 或元/吨 等，根据物品的类型来定
//     */
//    @Column(precision = 23, scale = 2)
//    private BigDecimal suggestPrice;
//    /**
//     * 单位类型 1.元/吨 2.元/KG 3.个
//     */
//    @Column(length = 11)
//    private Integer unitType;


//    /**
//     * 核价建议
//     */
//    @Column(length = 1024)
//    private String remark;
    /**
     * 配图的OSS对象名称
     */
    @Column(length = 128)
    private String img;

    /**
     * 可以逻辑删除
     */
    @Column(length = 1, columnDefinition = "INTEGER DEFAULT 1")
    private Integer flag;

    @JsonIgnoreProperties(value = {"recycleType", "saleType"})
    @Transient
    private RecycleTypePrice itemPrice;


    public Integer getSort() {
        if (sort == null)
            sort = 0;
        return sort;
    }

    public String getDownloadUrl() {
        return MyApplicationListener.publicProjectPath + img;
    }


}
